# -*- coding: utf-8 -*-
# https://blog.csdn.net/weixin_52040868
# 公众号：测个der
# 微信：qing_an_an


import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *


class Draw(QWidget):
    def __init__(self):
        super(Draw, self).__init__()
        self.setWindowTitle("在窗口中绘制文字 例子")

        self.text = "WelCome 测试小屋"

    # 重写父类
    def paintEvent(self, event):
        paint = QPainter(self)
        paint.begin(self)
        # 自定义绘制方法
        self.drawText(event, paint)
        paint.end()

    def drawText(self, event, qp):
        # 设置字体颜色
        qp.setPen(QColor(168, 34, 5))
        # 设置字体样式
        qp.setFont(QFont("微软雅黑", 20))
        # 绘制文字
        qp.drawText(event.rect(), Qt.AlignCenter, self.text)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    draw = Draw()
    draw.show()
    sys.exit(app.exec_())
